<%--
  Created by IntelliJ IDEA.
  User: 李煜湾
  Date: 2020/12/19
  Time: 21:15
  To change this template use File | Settings | File Templates.
  做一次更改
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>栏目管理</title>
    <script>
        // 实现删除确定，并且向news/queryNewLabel方法提交请求，附带参数deleId="+id，使用字符拼接方式进行传参
        function del(id)
        {
            var  str = confirm("是否确定删除上级栏目？");
            if(str == true)
            {
                window.location.href="${pageContext.request.contextPath}/news/queryNewLabel?deleId="+id;
                alert("确定删除！");
            }
            else
            {
                alert("取消删除！");
            }
        }
        // 上一页防首页方法实现
        function before(){
            var pagenum=${page.pagenum};
            if (pagenum==1){
                alert("当前页已经是首页！");
            }else {
                window.location.href="${pageContext.request.contextPath}/news/queryNewLabel?pagenum=${page.pagenum-1}&parentId=${parentId}";
            }
        }
        // 下一页防末页方法实现
        function after(){
            var pagenum=${page.pagenum};
            if(pagenum==${page.totalPages}){
                alert("当前页已经是末页！")
            }else {
                window.location.href="${pageContext.request.contextPath}/news/queryNewLabel?pagenum=${page.pagenum+1}&parentId=${parentId}"
            }
        }
        // 计划通过点击父栏目直接发送请求进行跳转，但是使用此方法实现有难度，就使用按钮代替
        function parent(id) {
            window.location.href="${pageContext.request.contextPath}/news/queryNewLabel?parentId="+id;
        }
    </script>
    <link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css">
    <script language="javascript" src="${pageContext.request.contextPath}/js/util.js"></script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td height="25" align="center" valign="bottom" class="td06"><table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="2%" valign="middle" background="../../images/bg_03.gif">&nbsp;</td>
                    <td width="2%" valign="middle" background="../../images/bg_03.gif"><img src="../../images/main_28.gif" width="9" height="9" align="absmiddle"></td>
                    <td height="30" valign="middle" background="../../images/bg_03.gif"><div align="left"><font color="#FFFFFF">栏目管理</font></div></td>
                </tr>
            </table></td>
        </tr>
    </table>
    <form name="form1" method="post" action="${pageContext.request.contextPath}/news/queryNewLabel">
        <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="table01">
            <tr>
                <td colspan="2" class="td_02"><SPAN class=td_title>根据栏目名称查询</SPAN></td>
            </tr>
            <tr>
                <td width="14%" class="td_02">栏目名称</td>
                <td width="86%" class="td_02">
                    <select name="parentId" id="parentId" class="input" style="width:84% ">
                        <option value=""> --请选择--</option>
                        <!-- 通过约束使用foreach循环遍历出pid=0的栏目作为父栏目 -->
                        <!-- 通过if语句进行判断，在文本框中默认显示父栏目 -->
                        <c:forEach items="${page.getParents()}" var="parent">
                            <option value="${parent.id}" 
                        
                                    <c:if test="${parent.id==parentId}">
                                        selected
                                    </c:if>
                            >
                                    ${parent.label_name}
                            </option>
                        </c:forEach>
                    </select>
                    <!-- 由于没有实现点击父栏目就跳转的功能，就添加了提交按钮来进行请求提交 -->
                    <button style="width: 5% ;height: 10%; padding: 3px;" type="submit">
                        提 交
                    </button>
                </td>
            </tr>
        </table>
        <br>
        <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td class="td_page" align="left">
                    <div align="right">
                        <button class="buttonface02">
                            <!-- 通过点击向news/selectByParents方法提交请求 -->
                            <a href="${pageContext.request.contextPath}/news/selectByParents">添加栏目</a>
                        </button>
                    </div></td>
            </tr>
        </table>
        <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="table01">

            <tr>
                <td colspan="5" align="right" class="td07"><img src="../../images/1.gif" width="4" height="5" align="absmiddle">
                <!-- 通过点击向news/selectByParents提交请求，且提交参数pagenum=1 -->
                        <a href="${pageContext.request.contextPath}/news/queryNewLabel?pagenum=1&parentId=${parentId}">首页</a>　
                        <img src="../../images/2.gif" width="3" height="5" align="absmiddle">
                        <!-- 为了防止代码块重复，使用点击事件方法before -->
                        <a onclick="before()" href="#">上一页</a>


                    <img src="../../images/2-2.gif" width="3" height="5" align="absmiddle">
                    <!-- 使用after方法 -->
                    <a onclick="after()" href="#">下一页</a>　
                    <img src="../../images/3.gif" width="4" height="5" align="absmiddle">
                    <!-- 向 news/queryNewLabel提交请求，且参数pagenum=${page.totalPages}动态获取末页值-->
                        <a href="${pageContext.request.contextPath}/news/queryNewLabel?pagenum=${page.totalPages}&parentId=${parentId}">末页</a>　　
                        <!-- 动态获取数据 -->
                    第 ${page.pagenum} 页 共 ${page.totalPages} 页 ${page.totalRows} 条记录
                </td>
            </tr>
            <tr>
                <td width="17%" class="td_top">栏目名称</td>
                <td width="15%" class="td_top">上级栏目名称</td>
                <td width="44%" class="td_top">栏目描述</td>
                <td width="12%" class="td_top">删除</td>
                <td width="12%" class="td_top">修改</td>
            </tr>
            <!-- 使用forEach方法对数据进行遍历 -->
            <c:forEach items="${page.getDatas()}" var="data">
                <tr>

                    <td hidden id="${data.id}" >${data.id}</td>
                    <td class="td07">${data.label_name}</td>
                    <td class="td07">${data.parent.label_name}</td>
                    <td class="td07">${data.label_content}</td>
                    <!-- 使用del方法进行删除 -->
                    <td class="td07"><a  onClick="del(${data.id})"
                                         href="#">删除</a></td>
                    <!-- 使用news/selectNew方法，且提交参数id=${data.id} -->
                    <td class="td07"><a href="${pageContext.request.contextPath}/news/selectNew?id=${data.id}">
                        修改</a>
                    </td>
                </tr>

            </c:forEach>

            
        </table>
        <p>&nbsp;</p>
    </form>
</center>
</body>
</html>
